package com.vankimgps.activity;

import java.io.IOException;

import com.vankimgps.database.DatabaseHelper;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		DatabaseHelper db = new DatabaseHelper(this);
	
		try {
			db.createDataBase();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// checking login
		Log.i("VANKIM","VANKIM: Login " + db.getLogin());

		if (db.getLogin()){
			Intent intent = new Intent(this,TrackingActivity.class);				
			startActivity(intent);
		}else{
			Intent intent = new Intent(this,LoginActivity.class);
			startActivity(intent);
		}
		finish();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch(item.getItemId())
	    {
	    case R.id.menu_tracking:{
			Intent intent = new Intent(this,TrackingActivity.class);				
			startActivity(intent);
			finish();
	    }
	        break;
	    case R.id.menu_finding:{
			Intent intent = new Intent(this,FindingActivity.class);				
			startActivity(intent);
			finish();
	    }
	        break;
	    case R.id.menu_settings:{
			Intent intent = new Intent(this,SettingsActivity.class);				
			startActivity(intent);
			finish();
	    }
	        break;
	    case R.id.menu_aboutus:{
			Intent intent = new Intent(this,AboutUsActivity.class);				
			startActivity(intent);
			finish();
	    }
	        break;
	    } 
	    return true;
	}
}
